package com.jcfk.eam.controller.bd;

import com.jcfk.common.web.domain.*;
import com.jcfk.eam.domain.dto.base.EamAssetPositionDTO;
import com.jcfk.eam.domain.dto.main.EamCheckAnomalyTrackingDTO;
import com.jcfk.eam.domain.query.base.EamAssetPositionQuery;
import com.jcfk.eam.domain.query.base.EamSopItemQuery;
import com.jcfk.eam.domain.query.main.EamCheckAnomalyTrackingQuery;
import com.jcfk.eam.service.base.EamAssetPositionService;
import com.jcfk.eam.service.main.EamCheckAnomalyTrackingService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 巡点检异常跟踪
 */
@RestController
@RequestMapping("anomaly/tracking")
public class EamCheckAnomalyTrackingController {


    @Autowired
    private EamCheckAnomalyTrackingService eamCheckAnomalyTrackingService;
    /**
     * 分页列表
     */
    @ApiImplicitParams({
        @ApiImplicitParam(paramType = "body", dataType = "ReqPageParam<EamCheckAnomalyTrackingQuery>", name = "requestParam", value = "", required = true)
    })
    @ApiOperation("分页巡点检异常跟踪")
    @PostMapping("/queryByPage")
    public RetPage<EamCheckAnomalyTrackingDTO> queryByPage(@RequestBody ReqPageParam<EamCheckAnomalyTrackingQuery> requestParam) {
        if (requestParam.getSort().getOrderItem() == null) {
            ReqSortParam<EamCheckAnomalyTrackingQuery> sortParam = new ReqSortParam();
            sortParam.setColumn("workTime");
            sortParam.setOrderBy("desc");
            requestParam.setSort(sortParam);
        }

        DataPage<EamCheckAnomalyTrackingDTO> page = new DataPage<EamCheckAnomalyTrackingDTO>((long) requestParam.getCurrent(),
            (long) requestParam.getSize(),
            requestParam.getSort().getOrderItem(),
            EamCheckAnomalyTrackingDTO.class);
        page = eamCheckAnomalyTrackingService.queryByPage(page, requestParam.getData());

        return new RetPage<>(page);
    }

    /**
     * 异常关闭
     */
    @PostMapping("/close")
    public RetResult<?> close(@RequestBody EamCheckAnomalyTrackingDTO dto) {
        eamCheckAnomalyTrackingService.close(dto.getCheckDetailId(), dto.getRemarks());
        return RetResult.ok();
    }
}
